<?php
namespace API\Controller;
use Think\Controller;
class ActivityController extends Controller
{

    /*1.查看活动列表*/
      public function getActivitylist(){
        //调用模型层获取数据
        $activitysmodel=M('activity');
        $activitys=$activitysmodel->select();
        $this->ajaxReturn($activitys,'JSON');

    }
  

  /*2.查看活动详情*/
     public function getDetail(){ 
        $act_id=$_GET['act_id'];
        //调用模型层获取数据
        $detailmodel=M('activity');
        $detail=$detailmodel->find($act_id);
        //调用视图层显示数据
        $this->detail=$detail;
        $this->ajaxReturn($detail,'JSON');

    }



   

   /*3.报名活动*/
    // public function enterActivity(){
    //     $enterModel=M('enter'); 
    //     $data['u_id']=$_GET['u_id'];
    //     $data['act_id']=$_GET['act_id'];
    //     $data['e_name']=$_GET['e_name'];
    //     $data['e_email']=$_GET['e_email'];
    //     $data['e_address']=$_GET['e_address'];
    //     $data['e_remarks']=$_GET['e_remarks'];
    //     $data['e_time'] = array('exp','now()'); 

      

    //      $enter=$enterModel->add($data);
    //         if(false !=$enter){          
    //        $senting = array('success'=>1);
    //         echo json_encode($senting);
    //         } 
    // }

   public function enterActivity(){
        $enterModel=M('enter'); 
        $data['u_id']=$_GET['u_id'];
        $data['act_id']=$_GET['act_id'];
      

       $num = $enterModel -> where($data) -> count();
          if(0 == $num){
               $data['e_name']=$_GET['e_name'];
               $data['e_email']=$_GET['e_email'];
               $data['e_address']=$_GET['e_address'];
               $data['e_remarks']=$_GET['e_remarks'];
               $data['e_time'] = array('exp','now()'); 

             $enter=$enterModel->add($data);

                     if(false !=$enter){
                          $senting = array('success'=>1);
                          echo json_encode($senting);
                    }else{
        //$this->false;
                          $senting = array('success'=>0);
                          echo json_encode($senting);
                       }
                    }         
                  else{
                        $senting = array('success'=>2);
                         echo json_encode($senting);
                        /**重复报名*/
                       }                      

}


}

